<?php
use Phalcon\Di\FactoryDefault;
define('ENVIRONMENT', isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'development');

switch (ENVIRONMENT) {
    case 'development':
        error_reporting(E_ALL);
        //error_reporting(-1);
        ini_set('display_errors', 1);
        ini_set('log_errors', '1');
        break;

    case 'production':
        ini_set('display_errors', 0);
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
        break;

    default:
        header('HTTP/1.1 503 Service Unavailable.', true, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}

define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

if (ENVIRONMENT == 'development') {
    try {
        $di = new FactoryDefault();
        include APP_PATH . '/config/router.php';
        include APP_PATH . '/config/services.php';
        $config = $di->getConfig();
        include APP_PATH . '/config/loader.php';
        require APP_PATH . '/../vendor/autoload.php';
        $application = new \Phalcon\Mvc\Application($di);
        echo $application->handle()->getContent();
    } catch (\Exception $e) {
        echo $e->getMessage() . '<br>';
        echo '<pre>' . $e->getTraceAsString() . '</pre>';
    }
}
if (ENVIRONMENT == 'production') {
    $di = new FactoryDefault();
    include APP_PATH . '/config/router.php';
    include APP_PATH . '/config/services.php';
    $config = $di->getConfig();
    include APP_PATH . '/config/loader.php';
    require APP_PATH . '/../vendor/autoload.php';
    $application = new \Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();
}
